// NativeGate.h

#include <string.h>
#pragma once

using namespace System;
using namespace System::Runtime::InteropServices;

namespace NativeGate {

	public ref class Util
	{
	private :
		static unsigned short Key_Length=18;

		// TODO: Add your methods for this class here.
	public :char* GetNativeStringFromManaged(System::String^ strSource)
			{
				IntPtr h=Marshal::StringToHGlobalAnsi(strSource);
				char* nativeString=(char*)(void*)h;
				int length=::strlen(nativeString);

				char* result=new char[length+1];

				strcpy_s(result,length+1,nativeString);

				Marshal::FreeHGlobal(h);

				return result;
			}

			//Validation key
	public :bool LicenseKeySimplestValidation(System::String^ key)
			{
				bool result=false;
				try

				{
					char* lKey=GetNativeStringFromManaged(key);
					if(strlen(lKey)==Key_Length)
					{
						result=true;
					}

				}
				catch(...)
				{
					return false;
				}

				return result;
			}


	};
}
